package com.check.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.check.pojo.MarkData;
import com.check.pojo.PageObject;
import com.check.pojo.Pcwh;
import com.check.service.MarkDataService;
import com.check.service.PcwhService;

@Controller
public class MarkStatusController extends BaseController{

	@Autowired
	@Qualifier("pcwhService")
	private PcwhService pcwhService;
	
	@Autowired
	@Qualifier("markDataService")
	private MarkDataService markDataService;
	
	@RequestMapping("markStatus1.do")
	public ModelAndView markStatus1(HttpServletRequest request,HttpServletResponse response){
		List<Pcwh> pcwhList = pcwhService.findAllPcwh();
		return new ModelAndView("page/markStatus/markStatus")
					.addObject("path",request.getContextPath())
					.addObject("pcwhList",pcwhList);
	}
	
	@RequestMapping("markStatusResult1.do")
	public ModelAndView markStatusResult1(HttpServletRequest request,HttpServletResponse response,
			@ModelAttribute("markData")MarkData markData,@ModelAttribute("pageObject")PageObject pageObject){
	
		if(pageObject.getCurrent()==0){
			pageObject.setCurrent(1);
		}
		pageObject.setUrl("markStatusResult.do?checkYear="+markData.getCheckYear()+"&");
		
		if("0".equals(markData.getExpType())){
			List dataList=markDataService.findAgencyMarkStatus(markData,pageObject);
			pageObject.setTotal(markDataService.findAgencyMarkStatusCount(markData));
			return new ModelAndView("page/markStatus/markStatusResult2")
			.addObject("path",request.getContextPath())
			.addObject("page",pageObject.toPage())
			.addObject("dataList",dataList);
		}else{
			List dataList=markDataService.findPersonMarkStatus(markData,pageObject);
			pageObject.setTotal(markDataService.findPersonMarkStatusCount(markData));
			return new ModelAndView("page/markStatus/markStatusResult")
			.addObject("path",request.getContextPath())
			.addObject("page",pageObject.toPage())
			.addObject("dataList",dataList);
		}
	}
	
	
	@RequestMapping("markStatus.do")
	public ModelAndView markStatus(HttpServletRequest request,HttpServletResponse response){
		List<Pcwh> pcwhList = pcwhService.findAllPcwh();
		return new ModelAndView("page/markStatus/markStatus")
					.addObject("path",request.getContextPath())
					.addObject("pcwhList",pcwhList);
	}
		
	@RequestMapping("markStatusResult.do")
	public ModelAndView markStatusResult(HttpServletRequest request,HttpServletResponse response,
			@ModelAttribute("markData")MarkData markData,@ModelAttribute("pageObject")PageObject pageObject){
	
		if(pageObject.getCurrent()==0){
			pageObject.setCurrent(1);
		}
		if(markData.getCheckYear()==null){
			markData.setCheckYear("");
		}
		pageObject.setUrl("markStatusResult.do?checkYear="+markData.getCheckYear()+"&");
		List dataList=markDataService.findQueryMarkStatus(markData,pageObject);
		pageObject.setTotal(markDataService.findQueryMarkStatusCount(markData));
		String checkYear=markData.getCheckYear();
		return new ModelAndView("page/markStatus/markStatusQueryResult")
					.addObject("path",request.getContextPath())
					.addObject("page",pageObject.toPage())
					.addObject("dataList",dataList)
					.addObject("checkYear",checkYear);
		
	}
	
	@RequestMapping("markStatusResultDetail.do")
	public ModelAndView markStatusResultDetail(HttpServletRequest request,HttpServletResponse response,
			@ModelAttribute("pageObject")PageObject pageObject){
		String deptId = request.getParameter("deptId");
		String checkYear=request.getParameter("checkYear");
		if(pageObject.getCurrent()==0){
			pageObject.setCurrent(1);
		}
		pageObject.setUrl("markStatusResultDetail.do?deptId="+deptId+"&checkYear="+checkYear+"&");
		List dataList=markDataService.findQueryMarkStatusDetailByDeptId(deptId,checkYear,pageObject);
		pageObject.setTotal(markDataService.findQueryMarkStatusDetailByDeptIdCount(deptId,checkYear));
		return new ModelAndView("page/markStatus/markStatusQueryResultDetail")
				.addObject("path",request.getContextPath())
				.addObject("dataList",dataList)
				.addObject("page",pageObject.toPage())
				.addObject("checkYear",checkYear);
				
	}
	
}
